/* 
按照图书的ISBN到中国版本出版社官网查询图书的详细信息
*/
var axios = require('axios');
// var capubToString = require('./capubToString2');
var chunkTest = require('./chunk-test');
var config = require('./chunk-config');

function myParse(obj) {
  let str = "";
  let arr = Object.keys(obj);
  arr.forEach((item, index) => {
    let value = obj[item];
    str += encodeURIComponent(item) + "=" + encodeURIComponent(value);
    if (index != arr.length - 1) {
      str += "&"
    }
  })
  console.log('', str)
  return str
}

let i = chunkTest["e82a"];
function responseHandle_a(t) {
  var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "zg35ws76swnxz679"
    , s = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "z66qa18l0w9o521k"
    , a = i["enc"].Utf8.parse(e)
    , n = i["enc"].Utf8.parse(s)
    , o = i["AES"].decrypt(t, a, {
      iv: n,
      mode: i["mode"].CBC,
      padding: i["pad"].Pkcs7
    });
  return o.toString(i["enc"].Utf8)
}

axios({
  method: 'POST',
  url: 'https://pdc.capub.cn/api/index/searchQuick',
  data: myParse({
    pageNum: 1,
    pageSize: 10,
    keyword: "978-7-02-000872-8",
    // publishingStart: "",
    // publishingEnd: "",
    // createdateStart: "",
    // createdateEnd: "",
    // auditdateStart: "",
    // auditdateEnd: "",
    // cate: "",
    // ztc: "",
    // zz: "",
    // cbn: "",
    // publisher: "",
    stat: 0,
    download: 0,
    // ids: "",
    searchType: "cip,marc",
    // sortName: "",
    // sortType: "",
    "ztype[0]": "CIP",
    "ztype[1]": "馆藏",
    search_type: "book",
    // filterzz: "",
    operateUrl: "快速检索",
  }),
  headers: {
    // Accept: "application/json,text/plain,*/*",
    // "Accept-Encoding": "gzip,deflate,br",
    // "Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
    // Connection: "keep-alive",
    // "Content-Length": 357,
    // "Content-Type": "application/x-www-form-urlencoded",
    // Host: "pdc.capub.cn",
    // Origin: "https://pdc.capub.cn",
    // Referer: "https://pdc.capub.cn/search.html",
    // // "sec-ch-ua": '".Not/A)Brand";v="99","Google Chrome";v="103","Chromium";v="103"',
    // // "sec-ch-ua-mobile": "?0",
    // // "sec-ch-ua-platform": "Windows",
    // // "Sec-Fetch-Dest": "empty",
    // // "Sec-Fetch-Mode": "cors",
    // // "Sec-Fetch-Site": "same-origin",
    // // "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
    userSessionId: config.token,// 主要，用于判断是否有用户登录。从缓存user-token中获取
    Cookie: "JSESSIONID=" + config.JSESSIONID,
  },
}).then(function (response) {
  // { status: 'failed', msg: '没有用户' }
  // console.log(response);
  if (response.data && response.data.code == "0") {
    let result = JSON.parse(responseHandle_a(response.data.result))
    console.log('', result)
    result.list.forEach(element => {
      console.log('', element.firstbookname)
    });
  }
}).catch(function (error) {
  console.log(error);
});


// let res = responseHandle_a()

// console.log('res === ', res)